package com.winter.controller;

/**
 * Created by lenovo on 2016/12/6.
 */

import com.winter.entity.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@EnableAutoConfiguration
public class SampleController {

    protected static Logger logger= LoggerFactory.getLogger(SampleController.class);

    @RequestMapping("/")
    @ResponseBody
    String home() {
        logger.debug("访问hello");
        return "Hello World!";
    }

    @RequestMapping("/hello/{myName}")
    @ResponseBody
    String index(@PathVariable String myName) {
        logger.debug("访问helloName,myName={}",myName);
        return "Hello "+myName+"!!!";
    }

    @RequestMapping("/person/{name}")
    @ResponseBody
    Person person(@PathVariable String name) {
        Map<String, Person> personMap = new HashMap<>();
        Person mother = new Person("Lucy", 48, new Date(), "女");
        Person son = new Person("Tom", 12, new Date(), "男");
        son.setParent(mother);
        personMap.put(mother.getName(), mother);
        personMap.put(son.getName(), son);
        logger.debug("访问person,person={}",personMap.get(name));
        return personMap.get(name);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}
